from django.contrib.auth import get_user_model
from rest_framework import serializers, viewsets
from rest_framework import mixins
from rest_framework.viewsets import GenericViewSet
from rest_framework.generics import GenericAPIView,ListAPIView
User = get_user_model()


# 定义序列化数据 把user表里面的 url username mail is_staff字段提取出来
class UserSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        # 使用哪个数据模型
        model = User
        # 序列化哪些字段出来
        fields = ('url', 'username', 'email', 'is_staff')


# view视图函数, 展示数据 和我们之前的 类视图一样 一样需要继承某些类来实现特定的方法
class UserViewSet(viewsets.ModelViewSet):
    # queryset 表示查询哪些数据
    queryset = User.objects.all()
    # serializer_class 表示我们使用哪些序列化类来展示数据
    serializer_class = UserSerializer



from rest_framework.response import Response

class UserSerialzier(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = "__all__"

class Test2(mixins.ListModelMixin,mixins.DestroyModelMixin,GenericAPIView):
    """
    Concrete view for listing a queryset.
    """
    pass



class Test3(mixins.ListModelMixin,mixins.UpdateModelMixin,GenericViewSet):
    pass





